package com.tarena.sentinel.demo02;

import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class SentinelMain {
    public static void main(String[] args) {
        SpringApplication.run(SentinelMain.class,args);

        //定义一个流控规则list
        List<FlowRule> flowRules = new ArrayList<>();
        // 流控规则对象
        FlowRule flowRule = new FlowRule();
        // 3个必要属性
        // 绑定资源名称(控制器资源名称)
        flowRule.setResource("resource01");
        // 0-并发限流 \ 1-每秒请求数(QPS)
        flowRule.setGrade(1);
        // 设置阈值(请求数的上限)
        flowRule.setCount(1);
        // 将流控规则对象添加到集合对象中
        flowRules.add(flowRule);
        // 注册到Sentinel供其使用
        FlowRuleManager.loadRules(flowRules);

    }
}
